package com.niit.covid.MeiTuanStaterjoin;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class JoinDriver extends Configured implements Tool {
    @Override
    public int run(String[] args) throws Exception {
        //创建作业实例
        Job job = Job.getInstance(getConf(), JoinDriver.class.getSimpleName());
        //设置作业驱动类
        job.setJarByClass(JoinDriver.class);

        //设置作业mapper reduce类
        job.setMapperClass(JoinMapper.class);
        job.setReducerClass(JoinReduce.class);

        //设置作业mapper 阶段输出key\value数据类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Text.class);

        //设置作业reduce阶段输出key value数据类型 ，也就是最终的输出数据类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        //配置作业的输入数据路径
        FileInputFormat.addInputPath(job,new Path("input/covid/MapReducejoin"));
        //配置作业的输出路径
        FileOutputFormat.setOutputPath(job, new Path("output/covid/join"));

        //提交作业并等待执行完成
        return  job.waitForCompletion(true) ? 0:1;


    }

    public static void main(String[] args) throws Exception {
        //配置文件对象
        Configuration conf = new Configuration();
        //使用工具类ToolRunner提交程序
        int status = ToolRunner.run(conf,new JoinDriver(),args);
        //退出各户端程序 客户端退出状态码和mapreduce程序执行结果绑定
        System.exit(status);
    }


}
